
const merge = require('webpack-merge');
const webpack = require('webpack');

const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const HtmlWebpackExternalsPlugin = require('html-webpack-externals-plugin');

const baseConfig = require('./webpack.base');

const prodConfig = {
	mode: 'production',

	plugins: [
		// 压缩css
		new OptimizeCssAssetsPlugin({
			assetNameRegExp: /\.css$/g,
			cssProcessor: require('cssnano'),
		}),
		new webpack.DllReferencePlugin({
			manifest: require('./build/library/library.json')
		})
		//
		// new HtmlWebpackExternalsPlugin({
		// 	externals: [
		// 		{
		// 			module: 'react',
		// 			entry: "https://unpkg.com/react@16/umd/react.production.min.js",
		// 			global: 'React',
		// 		},
		// 	],
		// }),
		// new HtmlWebpackExternalsPlugin({
		// 	externals: [
		// 		{
		// 			module: 'react-dom',
		// 			entry: 'https://unpkg.com/react-dom@16/umd/react-dom.production.min.js',
		// 			global: 'ReactDOM',
		// 		},
		// 	],
		// })
	],

	optimization: {
		minimize:true,
		minimizer:[
			new TerserPlugin({
				parallel:true
			})
		],
		splitChunks: {
			chunks: 'all',
			minSize: 30000,
			maxSize: 0,
			minChunks: 1,
			maxAsyncRequests: 5,
			maxInitialRequests: 3,
			automaticNameDelimiter: '--', // 分包打包生成文件的名称的连接符
			cacheGroups: {
				// commons:{
				// 	test: /(react|react-dom)/,
				// 	name:'vendors',
				// 	chunks: "all",
				// },
				commons: {
					name: 'commons',
					chunks: 'all',
					minChunks: 2,
				},
			},
		},
	},

};

module.exports = merge(baseConfig, prodConfig);
